/**
 * 
 */
package com.android.hw.projectmenu;

import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.text.TextUtils;
import android.util.Log;
import android.os.SystemProperties;
/**
 * @author gaoshengpan
 *
 */
public class ShowHwSoftInfo extends PreferenceActivity {
	private static final String KEY_HW_VERSION = "hw_version";
	private static final String KEY_HW_INTERNAL_VERSION = "hw_internal_version";
	private static final String KEY_APCOM_TIME = "apcom_time";
    private static String mUnknown = "null";
    private String TAG = "ShowHwSoftInfo";
	/**
	 * 
	 */
	public ShowHwSoftInfo() {
		// TODO Auto-generated constructor stub
	}
	
	@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.hw_soft_info);
    }

	 private void setSoftwareVersion() {
	        String softwareTitle = getSystemproString("ro.build.display.id");
	        String internalSoftwareTitle = getSystemproString("ro.build.cust.id");
	        /*gaoshenpan 15-08-20 fix hw-comptime begin*/
	        String softwareTime = getSystemproString("ro.build.date");
	        /*gaoshenpan 15-08-20 fix hw-comptime end*/
			Log.d(TAG, "softwareTime------->" + softwareTime);
			/*gaoshenpan 15-11-11 fix just use ro.build.date as ap-comptime & no need split begin*/
			/*if (softwareTime.length() > 18) {
				int nPos = softwareTime.indexOf(".");
				nPos = softwareTime.indexOf(".", nPos);
				softwareTime = softwareTime.substring(nPos + 1);
				Log.d(TAG, "softwareTime------->1" + softwareTime);
				nPos = softwareTime.indexOf(".");
				nPos = softwareTime.indexOf(".", nPos);

				softwareTime = softwareTime.substring(nPos + 1);
				Log.d(TAG, "softwareTime------->2" + softwareTime);

				StringBuffer time = new StringBuffer(softwareTime);
				time.insert(4, '-');
				time.insert(7, '-');
				
				 * time.replace(10, 11, " "); time.insert(13, ':'); time.insert(16,
				 * ':');
				 
				softwareTime = time.toString();
			}*/
			
			/*gaoshenpan 15-11-11 fix just use ro.build.date as ap-comptime & no need split end*/
			setSummaryText(KEY_APCOM_TIME, softwareTime);
	        setSummaryText(KEY_HW_VERSION, softwareTitle);
	        setSummaryText(KEY_HW_INTERNAL_VERSION, internalSoftwareTitle);
	    }
	 
	 private static String getSystemproString(String property) {
	        return SystemProperties.get(property, "unknown");
	    }
	 
	 /* (non-Javadoc)
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		setSoftwareVersion();
	}
	
	private void setSummaryText(String preferenceKey, String value) {
        Preference preference = findPreference(preferenceKey);
        if (preference == null)
            return;

        if (TextUtils.isEmpty(value))
            preference.setSummary(mUnknown);
        else
            preference.setSummary(value);
    }
}
